// 删除信息

console.log(msgData);

const vBox = document.querySelector('.msg');

var data = msgData.data;

render(data);

function render(data) {
  vBox.innerHTML = '';
  var html = '';
  console.log(data.length);
  for (let i = 0; i < data.length; i++) {
    html += `<div class="user">
          <div class="user_left">
            <div class="avatar">
              <img src="${data[i].img}" alt="" />
            </div>
            <div class="info">
              <span class="username">${data[i].username}</span>
              <span class="message">${data[i].desc}</span>
            </div>
          </div>
          <div class="user_right">
          <a href="javascript:;" id="${i}">x</a>
            <span>${data[i].date}</span>
          </div>
        </div>`;
  }

  vBox.innerHTML = html;
}

vBox.addEventListener('click', function (e) {
  if ((e.target.tagName === 'A')) {
    const index = e.target.getAttribute('id');
    data.splice(index, 1);
    render(data);
  }
});

// 展开消息
const  btn=document.querySelector('.open')
btn.addEventListener('click',function(){
    if(vBox.style.display==="block"){
        vBox.style.display="none"
        btn.innerText='展开'
    }else{
        vBox.style.display="block"
        btn.innerText='收起'
    }
})

// 跳转我的页面
const backLoc=document.querySelector('.backTo')
backLoc.addEventListener('click',function(){
  location.href="../pages/my.html"
})